{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8035a008-f29e-44ce-9760-3e59d175e6eb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "原始值：  a=0， b=88， c=96\n",
      "(方法一)升序值：  a=0， b=88， c=96\n",
      "(方法二)升序值：  a=0， b=88， c=96\n"
     ]
    }
   ],
   "source": [
    "import random,math\n",
    "a = random.randint(0,100)\n",
    "b = random.randint(0,100)\n",
    "c = random.randint(0,100)\n",
    "print(str.format(\"原始值：  a={0}， b={1}， c={2}\", a, b, c))\n",
    "a1 = a;b1 = b;c1 = c  # 保留a,b,c的值，以方便两种方法的比较\n",
    "#方法一：先a和b比较，使得a<b；然后a和c比较，使得a<c，此时a最小；最后b和c比较，使得b<c\n",
    "if (a > b):\n",
    "    t = a;a = b;b = t\n",
    "if (a > c):\n",
    "    t = a;a = c;c = t\n",
    "if (b > c):\n",
    "    t = b;b = c;c = t\n",
    "print(str.format(\"(方法一)升序值：  a={0}， b={1}， c={2}\", a, b, c))\n",
    "a = a1;b = b1;c = c1  # 恢复a,b,c的值，使用第二种方法\n",
    "#方法二：利用Max函数和Min函数求a、b、c三个数中最大数、最小数，而三个数之和减去最大数和最小数就是中间数\n",
    "Nmax = max(a, b, c)\n",
    "Nmin = min(a, b, c)\n",
    "Nmid = a + b + c - Nmax - Nmin\n",
    "a = Nmin;b = Nmid;c = Nmax\n",
    "print(str.format(\"(方法二)升序值：  a={0}， b={1}， c={2}\", a, b, c))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0305289c-f3ab-47ae-9673-f1d15df57fa2",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
